<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24" class="card-box">
        <el-card>
          <el-form
            :model="queryParams"
            ref="queryForm"
            :inline="true"
            v-show="showSearch"
            label-width="75px"
          >
            <el-form-item label="订单编号" prop="arriveBillNo">
              <el-input
                v-model="queryParams.arriveBillNo"
                placeholder="请输入订单编号"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="批次" prop="batchNo">
              <el-input
                v-model="queryParams.batchNo"
                placeholder="请输入批次"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="订单状态" prop="billStatus">
              <el-select
                v-model="queryParams.billStatus"
                placeholder="请选择订单状态"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in billStatusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button
                type="cyan"
                icon="el-icon-search"
                size="mini"
                @click="handleQuery"
                >搜索</el-button
              >
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
                >重置</el-button
              >
            </el-form-item>
          </el-form>

          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="primary"
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"
                v-hasPermi="['material:arriveBill:add']"
                >新增</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                icon="el-icon-edit"
                size="mini"
                :disabled="single"
                @click="handleUpdate"
                v-hasPermi="['material:arriveBill:edit']"
                >修改</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                :disabled="multiple"
                @click="handleDelete"
                v-hasPermi="['material:arriveBill:remove']"
                >删除</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="warning"
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                v-hasPermi="['material:arriveBill:export']"
                >导出</el-button
              >
            </el-col>
            <right-toolbar
              :showSearch.sync="showSearch"
              @queryTable="getList"
            ></right-toolbar>
          </el-row>

          <el-table
            v-loading="loading"
            :data="arriveBillList"
            @row-click="handleRowClick"
          >
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column
              label="订单编号"
              align="center"
              prop="arriveBillNo"
              width="120"
            />
            <el-table-column label="批次" align="center" prop="batchNo" />
            <el-table-column
              label="订单状态"
              align="center"
              prop="billStatus"
              :formatter="billStatusFormat"
            />
            <el-table-column
              label="收货完成人"
              align="center"
              prop="completeBy"
            />
            <el-table-column
              label="收货完成时间"
              align="center"
              prop="completeTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.completeTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="是否打印"
              align="center"
              prop="printStatus"
            />
            <el-table-column label="备注" align="center" prop="remark" />
            <el-table-column label="创建者" align="center" prop="createBy" />
            <el-table-column
              label="创建时间"
              align="center"
              prop="createTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.createTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column label="更新者" align="center" prop="updateBy" />
            <el-table-column
              label="更新时间"
              align="center"
              prop="updateTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.updateTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['material:arriveBill:edit']"
                  >修改</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['material:arriveBill:remove']"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
          <div style="position: absolute; height: 30px">
            <div style="margin-top: -20px; position: relative; float: left">
              <label for="">{{ queryDetailParams.toString }}</label>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row>
      <el-col class="card-box">
        <el-card>
          <el-form
            :model="queryDetailParams"
            ref="queryDetailForm"
            :inline="true"
            v-show="showDetailSearch"
            label-width="100px"
          >
            <el-form-item label="原材料编号" prop="materialNo">
              <el-input
                v-model="queryDetailParams.materialNo"
                placeholder="请输入原材料编号"
                clearable
                size="small"
                @keyup.enter.native="handleDetailQuery"
              />
            </el-form-item>
            <el-form-item>
              <el-button
                type="cyan"
                icon="el-icon-search"
                size="mini"
                @click="handleDetailQuery"
                >搜索</el-button
              >
              <el-button
                icon="el-icon-refresh"
                size="mini"
                @click="resetDetailQuery"
                >重置</el-button
              >
            </el-form-item>
          </el-form>

          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="primary"
                icon="el-icon-plus"
                size="mini"
                @click="handleDetailAdd"
                v-hasPermi="['material:arriveBillDetail:add']"
                >新增</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                icon="el-icon-edit"
                size="mini"
                :disabled="single"
                @click="handleDetailUpdate"
                v-hasPermi="['material:arriveBillDetail:edit']"
                >修改</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                :disabled="multiple"
                @click="handleDetailDelete"
                v-hasPermi="['material:arriveBillDetail:remove']"
                >删除</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="warning"
                icon="el-icon-download"
                size="mini"
                @click="handleDetailExport"
                v-hasPermi="['material:arriveBillDetail:export']"
                >导出</el-button
              >
            </el-col>
            <right-toolbar
              :showSearch.sync="showDetailSearch"
              @queryTable="getDetailList"
            ></right-toolbar>
          </el-row>

          <el-table
            v-loading="loading"
            :data="arriveBillDetailList"
            @selection-change="handleDetailSelectionChange"
          >
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleDetailUpdate(scope.row)"
                  v-hasPermi="['material:arriveBillDetail:edit']"
                  >修改</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleDetailCheck(scope.row)"
                  v-hasPermi="['material:arriveBillDetail:edit']"
                  >检验确认</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['material:arriveBillDetail:remove']"
                  >删除</el-button
                >
              </template>
            </el-table-column>
            <el-table-column
              label="订单编号"
              align="center"
              prop="arriveBillNo"
            />
            <el-table-column
              label="物料编号"
              align="center"
              prop="materialNo"
            />
            <el-table-column
              label="物料名称"
              align="center"
              prop="materialName"
            />
            <el-table-column label="规格" align="center" prop="materialSpec" />
            <el-table-column
              label="单位"
              align="center"
              prop="materialUnit"
              :formatter="materialUnitFormat"
            />
            <el-table-column label="单价" align="center" prop="price" />
            <el-table-column label="计划数量" align="center" prop="planNum" />
            <el-table-column label="合格数量" align="center" prop="actualNum" />
            <el-table-column
              label="供应商代码"
              align="center"
              prop="supplierNo"
            />
            <el-table-column
              label="供应商名称"
              align="center"
              prop="supplierName"
            />
            <el-table-column label="采购者" align="center" prop="buyBy" />
            <el-table-column
              label="采购时间"
              align="center"
              prop="buyTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.buyTime, "{y}-{m}-{d}") }}</span>
              </template>
            </el-table-column>
            <el-table-column label="检验者" align="center" prop="checkBy" />
            <el-table-column
              label="检验时间"
              align="center"
              prop="checkTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.checkTime, "{y}-{m}-{d}") }}</span>
              </template>
            </el-table-column>
            <el-table-column label="收货人" align="center" prop="recieveBy" />
            <el-table-column
              label="收货时间"
              align="center"
              prop="recieveTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.recieveTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column label="是否检验" align="center" prop="isChecked" />
            <el-table-column
              label="是否收货"
              align="center"
              prop="isRecieved"
            />
          </el-table>

          <pagination
            v-show="totalDetail > 0"
            :total="totalDetail"
            :page.sync="queryDetailParams.pageNum"
            :limit.sync="queryDetailParams.pageSize"
            @pagination="getDetailList"
          />
        </el-card>
      </el-col>
    </el-row>

    <!-- 添加或修改原料采购明细对话框 -->
    <el-dialog
      :title="titleDetail"
      :visible.sync="openDetail"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="formDetail"
        :model="formDetail"
        :rules="rulesDetail"
        label-width="100px"
      >
        <el-form-item label="订单编号" prop="arriveBillNo">
          <el-input v-model="formDetail.arriveBillNo" v-bind:disabled="true" />
        </el-form-item>

        <el-row>
          <el-col :span="18">
            <el-form-item label="物料编号" prop="materialNo">
              <el-input
                v-model="formDetail.materialNo"
                v-bind:disabled="true"
                placeholder="请选择物料"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6" align="center">
            <el-button type="primary" @click="selectMaterial"
              >选择物料</el-button
            >
          </el-col>
        </el-row>
        <el-form-item label="物料名称" prop="materialName">
          <el-input
            v-model="formDetail.materialName"
            v-bind:disabled="true"
            placeholder="请选择物料"
          />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="规格" prop="materialSpec">
              <el-input
                v-model="formDetail.materialSpec"
                v-bind:disabled="true"
                placeholder="请选择物料"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位" prop="materialUnit">
              <el-input
                v-model="formDetail.materialUnit"
                v-bind:disabled="true"
                placeholder="请选择物料"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="供应商编号" prop="supplierNo">
              <el-input
                v-model="formDetail.supplierNo"
                v-bind:disabled="true"
                placeholder="请选择供应商"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8" align="center">
            <el-button type="primary" @click="selectSupplier"
              >选择供应商</el-button
            >
          </el-col>
        </el-row>
        <el-form-item label="供应商名称" prop="supplierName">
          <el-input
            v-model="formDetail.supplierName"
            v-bind:disabled="true"
            placeholder="请选择供应商"
          />
        </el-form-item>
        <el-form-item label="单价" prop="price">
          <el-input v-model="formDetail.price" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="计划数量" prop="planNum">
          <el-input v-model="formDetail.planNum" placeholder="请输入计划数量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitDetailForm">确 定</el-button>
        <el-button @click="cancelDetail">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改采购订单对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单编号" prop="arriveBillNo">
          <el-input
            v-model="form.arriveBillNo"
            placeholder="系统自动生成"
            v-bind:disabled="true"
          />
        </el-form-item>
        <el-form-item label="批次" prop="batchNo">
          <el-input v-model="form.batchNo" placeholder="请输入批次" />
        </el-form-item>
        <el-form-item label="订单状态" prop="billStatus">
          <el-select
            v-model="form.billStatus"
            placeholder="请选择订单状态"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in billStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="openCheck"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <div>
        <el-form>
          <el-form-item label="合格数量" prop="actualNum">
            <el-input
              v-model="formDetail.actualNum"
              type="textarea"
              placeholder="请输入合格数量"
            />
          </el-form-item>
        </el-form>
        <div style="margin-top=10px;">
          <el-button type="primary" @click="submitCheckForm">确 定</el-button>
          <el-button @click="cancelCheck">取 消</el-button>
        </div>
      </div>
    </el-dialog>
    <SelectMaterialDialog
      v-bind:open="openM"
      v-on:select="handleSelectMaterial"
      v-on:cancel="cancelSelectMaterial"
    >
    </SelectMaterialDialog>

    <SelectSupplierDialog
      v-bind:open="openS"
      v-on:select="handleSelectSupplier"
      v-on:cancel="cancelSelectSupplier"
    >
    </SelectSupplierDialog>
  </div>
</template>

<script>
import {
  listArriveBill,
  getArriveBill,
  delArriveBill,
  addArriveBill,
  updateArriveBill,
  exportArriveBill
} from "@/api/material/arriveBill";

import {
  listArriveBillDetail,
  getArriveBillDetail,
  delArriveBillDetail,
  addArriveBillDetail,
  updateArriveBillDetail,
  exportArriveBillDetail
} from "@/api/material/arriveBillDetail";

import SelectMaterialDialog from "@/components/Simpsense/SelectMaterialDialog";
import SelectSupplierDialog from "@/components/Simpsense/SelectSupplierDialog";
export default {
  name: "ArriveBill",
  components: { SelectMaterialDialog, SelectSupplierDialog },
  data() {
    return {
      openCheck: false,
      openM: false,
      openS: false,
      //detail变量==============================================================================
      // 选中数组
      ids_d: [],
      // 非单个禁用
      single_d: true,
      // 非多个禁用
      multiple_d: true,
      // 显示搜索条件
      showDetailSearch: true,
      // 总条数
      totalDetail: 0,
      // 原料采购明细表格数据
      arriveBillDetailList: [],
      // 弹出层标题
      titleDetail: "",
      // 是否显示弹出层
      openDetail: false,
      // 查询参数
      queryDetailParams: {
        pageNum: 1,
        pageSize: 10,
        arriveBillNo: null,
        toString: null,
        materialNo: null
      },
      // 表单参数
      formDetail: {},
      // 表单校验
      rulesDetail: {
        arriveBillNo: [
          { required: true, message: "订单编号不能为空", trigger: "blur" }
        ],
        materialNo: [
          { required: true, message: "原材料编号不能为空", trigger: "blur" }
        ],
        supplierNo: [
          { required: true, message: "供应商代码不能为空", trigger: "blur" }
        ]
      },
      //detail变量==============================================================================
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购订单表格数据
      arriveBillList: [],
      materialUnitOptions: [],
      billStatusOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        arriveBillNo: null,
        batchNo: null,
        billStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        batchNo: [{ required: true, message: "批次不能为空", trigger: "blur" }]
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("bill_status").then(response => {
      this.billStatusOptions = response.data;
    });
    this.getDicts("smes_unit").then(response => {
      this.materialUnitOptions = response.data;
    });
  },
  methods: {
    /** 查询采购订单列表 */
    getList() {
      this.loading = true;
      listArriveBill(this.queryParams).then(response => {
        this.arriveBillList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        rowId: null,
        arriveBillNo: null,
        batchNo: null,
        billStatus: "0",
        completeBy: null,
        completeTime: null,
        printStatus: "N",
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    billStatusFormat(row, column) {
      return this.selectDictLabel(this.billStatusOptions, row.billStatus);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleRowClick(row) {
      this.queryDetailParams.arriveBillNo = row.arriveBillNo;
      this.queryDetailParams.toString = "当前选中订单：" + row.arriveBillNo;
      this.getDetailList();
    },
    // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.ids = selection.map(item => item.arriveBillNo);
    //   this.single = selection.length !== 1;
    //   this.multiple = !selection.length;
    // },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加采购订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const arriveBillNo = row.arriveBillNo || this.ids;
      getArriveBill(arriveBillNo).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改采购订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.arriveBillNo != null) {
            updateArriveBill(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addArriveBill(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const arriveBillNos = row.arriveBillNo || this.ids;
      this.$confirm(
        '是否确认删除采购订单编号为"' + arriveBillNos + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return delArriveBill(arriveBillNos);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有采购订单数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return exportArriveBill(queryParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    /** 查询原料采购明细列表 */
    getDetailList() {
      this.loading = true;
      listArriveBillDetail(this.queryDetailParams).then(response => {
        this.arriveBillDetailList = response.rows;
        console.log(this.arriveBillDetailList);
        this.totalDetail = response.total;
        this.loading = false;
      });
    },
    // 原料单位字典翻译
    materialUnitFormat(row, column) {
      return this.selectDictLabel(this.materialUnitOptions, row.materialUnit);
    },
    // 取消按钮
    cancelDetail() {
      this.openDetail = false;
      this.resetDetail();
    },
    // 表单重置
    resetDetail() {
      this.formDetail = {
        rowId: null,
        arriveBillNo: null,
        materialNo: null,
        materialName: null,
        materialSpec: null,
        materialUnit: null,
        price: null,
        planNum: null,
        actualNum: null,
        supplierNo: null,
        supplierName: null,
        buyBy: null,
        buyTime: null,
        checkBy: null,
        checkTime: null,
        recieveBy: null,
        recieveTime: null,
        isChecked: null,
        isRecieved: null
      };
      this.resetForm("formDetail");
    },
    /** 搜索按钮操作 */
    handleDetailQuery() {
      this.queryDetailParams.pageNum = 1;
      this.getDetailList();
    },
    /** 重置按钮操作 */
    resetDetailQuery() {
      this.resetForm("queryDetailForm");
      this.handleDetailQuery();
    },
    // 多选框选中数据
    handleDetailSelectionChange(selection) {
      this.ids_d = selection.map(item => item.rowId);
      this.single_d = selection.length !== 1;
      this.multiple_d = !selection.length;
    },
    /** 新增按钮操作 */
    handleDetailAdd() {
      this.resetDetail();
      if (this.queryDetailParams.arriveBillNo != null) {
        this.formDetail.arriveBillNo = this.queryDetailParams.arriveBillNo;
        this.openDetail = true;
        this.titleDetail = "添加原料采购明细";
      } else {
        this.msgInfo("请先选择采购订单！");
      }
    },
    /** 修改按钮操作 */
    handleDetailUpdate(row) {
      this.resetDetail();
      const rowId = row.rowId || this.ids_d;
      getArriveBillDetail(rowId).then(response => {
        this.formDetail = response.data;
        this.openDetail = true;
        this.titleDetail = "修改原料采购明细";
      });
    },
    handleDetailCheck(row) {
      this.resetDetail();
      const rowId = row.rowId || this.ids_d;
      getArriveBillDetail(rowId).then(response => {
        this.formDetail = response.data;
        this.formDetail.billStatus = 2;
        this.openCheck = true;
      });
    },
    /** 提交按钮 */
    submitDetailForm() {
      this.$refs["formDetail"].validate(valid => {
        if (valid) {
          if (this.formDetail.rowId != null) {
            updateArriveBillDetail(this.formDetail).then(response => {
              this.msgSuccess("修改成功");
              this.openDetail = false;
              this.getDetailList();
            });
          } else {
            addArriveBillDetail(this.formDetail).then(response => {
              this.msgSuccess("新增成功");
              this.openDetail = false;
              this.getDetailList();
            });
          }
        }
      });
    },
    selectMaterial() {
      this.openM = true;
    },
    handleSelectMaterial(data) {
      this.openM = false;
      this.formDetail.materialNo = data.materialNo;
      this.formDetail.materialName = data.materialName;
      this.formDetail.materialSpec = data.materialSpec;
      this.formDetail.materialUnit = data.materialUnit;
    },
    cancelSelectMaterial() {
      this.openM = false;
    },
    handleSelectSupplier(data) {
      this.openS = false;
      this.formDetail.supplierName = data.supplierName;
      this.formDetail.supplierNo = data.supplierNo;
    },
    cancelSelectSupplier() {
      this.openS = false;
    },
    selectSupplier() {
      this.openS = true;
    },
    /** 删除按钮操作 */
    handleDetailDelete(row) {
      const rowIds = row.rowId || this.ids_d;
      this.$confirm(
        '是否确认删除原料采购明细编号为"' + rowIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return delArriveBillDetail(rowIds);
        })
        .then(() => {
          this.getDetailList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleDetailExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有原料采购明细数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return exportArriveBillDetail(queryDetailParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    submitCheckForm() {
      if (this.formDetail.isChecked == "Y") {
        this.msgInfo("已检验！");
        return;
      }
      if (this.formDetail.actualNum > this.formDetail.planNum) {
        this.msgInfo("合格数量超出计划数量！");
        return;
      }
      this.formDetail.isChecked = "Y";
      updateArriveBillDetail(this.formDetail).then(response => {
        this.msgSuccess("修改成功");
        this.openCheck = false;
        this.getDetailList();
      });
    },
    cancelCheck() {
      this.openCheck = false;
    }
  }
};
</script>
